package com.zbkj.dal.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.zbkj.dal.entity.user.UserBalanceRecord;
import com.zbkj.dal.pojo.dto.MonthAmountItemDTO;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.math.BigDecimal;
import java.util.List;

/**
 * <p>
 * 用户余额记录表 Mapper 接口
 * </p>
 *
 * @author HZW
 * @since 2022-10-11
 */
public interface UserBalanceRecordDao extends BaseMapper<UserBalanceRecord> {

    @Select("select status as status, type as type ,sum(amount) as amount from eb_user_balance_record where uid = #{userId} and bill_date between #{begin} and #{end} and is_deleted = 0 group by status, type;")
    List<MonthAmountItemDTO> monthAmountItem(@Param("userId") Integer userId, @Param("begin") Integer begin, @Param("end") Integer end);

    @Select("select sum(r.amount) from eb_user_balance_record r where r.uid = #{userId} and r.status = #{status} and r.type = #{type} and r.is_deleted = 0;")
    BigDecimal totalByTypeAndStatus(@Param("userId")Integer userId,@Param("status")String status,@Param("type")String type);
}
